package com.forezp.datastruct.mapdata;

/**
 * 图数据库的数据结构的一种简单的实现方式
 * <p>
 * Created by forezp on 2017/12/11.
 */
public class CMap<T> {

    private int capacity;
    private int size;
    private CNode[] nodes;
    private int[] matrix;//可换成bridge


    public CMap(int capacity) {
        this.capacity = capacity;
        size = 0;
        nodes = new CNode[capacity];
        matrix = new int[capacity * capacity];
    }

    public boolean add(CNode<T> cNode) {
        if (cNode == null) {
            return false;
        }
        nodes[size++] = cNode;
        return true;
    }


    /**
     * 设置无相边
     *
     * @return
     */
    public boolean setNoOrientedBridge(int row, int col, int value) {
        if (row < 0 || row > capacity) {
            return false;
        }
        if (col < 0 || col > capacity) {
            return false;
        }
        matrix[row * capacity + col] = value;
        matrix[col * capacity + row] = value;
        return true;
    }

    /**
     * 设置有相边
     *
     * @return
     */
    public boolean setOrientedBridge(int row, int col, int value) {
        if (row < 0 || row > capacity) {
            return false;
        }
        if (col < 0 || col > capacity) {
            return false;
        }
        matrix[row * capacity + col] = value;
        return true;
    }


    public void reset() {
        for (int i = 0; i < size; i++) {
            nodes[i].isVisited = false;
        }
    }

    /**
     * 深度遍历
     */
    public void deepPrint(int row,int col) {

        //CNode cNode=nodes[]



    }

}
